<template>
    <div class="run">
        <DashHeader/>
        <el-main>
  
  <el-form ref="form" :model="form" label-width="120px">
    <h4>
        配置测试参数
    </h4>  
        <el-form-item label="测试类型">
      <el-select v-model="form.type" placeholder="select your type">
        <el-option label="功能测试" value="function">功能测试</el-option>
        <el-option label="性能测试" value="performance">性能测试</el-option>
      </el-select>
    </el-form-item>
     <el-form-item v-if="form.type==='function'" label="执行环境">
      <el-select v-model="form.env"  placeholder="select your environment">
        <el-option label="测试环境" value="test">测试环境</el-option>
        <el-option label="集成环境" value="instrg">集成环境</el-option>
      </el-select>
    </el-form-item>       
    
         <el-form-item v-if="form.type==='performance'" label="测试接口">     
        <el-input v-model="form.interfaces" style="width:300px" type="textarea">    
      </el-input>
    </el-form-item> 
  <el-form-item v-if="form.type==='performance'" label="对应用例">     
        <el-input v-model="form.testid" style="width:300px" type="textarea">    
      </el-input>
    </el-form-item> 
      <el-form-item v-if="form.type==='performance'" label="期望相应时间">     
        <el-input v-model="form.responsetime" style="width:300px" type="textarea">    
      </el-input>
    </el-form-item> 
         <el-form-item v-if="form.type==='performance'" label="期望TPS">     
        <el-input v-model="form.tps" style="width:200px" type="textarea">    
      </el-input>
    </el-form-item> 
    <el-form-item>
      <el-button type="primary" @click="onSubmit">创建</el-button>
    </el-form-item>
  </el-form>


  </el-main>
    </div>

</template>
<script>
import  DashHeader from '@/components/DashHeader'
export default {
     name: 'Config',
   components: {
       DashHeader
   },
  data() {
    return {            
   
      form: {       
        type: 'performance',            
        interfaces: "/opt/jmeter/bin/system.properties",  
        testid: 'aff4d321-7cc8-4ceb-8665-9f9241e61793'  

      },
    }
  },
  methods: {
    async onSubmit() {
      if (this.form.type === 'function') {
      var url = "/api/v1/operation/planjenkins";
           await this.$http.post(url,{            
                    'project':this.form.product,
                    'runningEnv':this.form.env,
                    'modules':this.form.modules,
                    'caseServerity': this.form.serverity,
                    'mailReceiver': this.form.email
                     })
                     .then(resp => {
               window.console.log(resp.data)
               this.planid = resp.data
           })
      } else {      
      var urlp = "/api/v1/operation/performance";
           await this.$http.post(urlp,{            
                    'id':this.form.interfaces[0],                   
                     })
                     .then(resp => {
               window.console.log(resp.data)
               this.planid = resp.data
           })
      }
            
           //提示执行成功
           var message =  '测试ID为：' + this.planid
           this.$alert(message, '测试开始执行', {
          confirmButtonText: '确定',
            callback: () => {
            this.$message({
              type: 'info',
              message: `开始测试`,
            })
          }, 
        })
        
       }
  },
}
</script>